package org.gd.hellojson.json;

import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.map.ObjectWriter;

import java.io.IOException;

/**
 * @author Gorhover
 * @version 1.0
 */
public class Json {

    public static String parse(Object instance, JsonProperty...properties)
            throws IOException {
        ObjectMapper mapper = new ObjectMapper();
        ObjectWriter writer = mapper.writer();
        for (JsonProperty property: properties ) {
            if(JsonProperty.FORMATTED.equals(property)) {
                writer = mapper.writerWithDefaultPrettyPrinter();
            }
        }
        return writer.writeValueAsString(instance);
    }

    public static <T> T parse(String json, Class<T> clazz, JsonProperty...properties)
            throws IOException {
        ObjectMapper mapper = new ObjectMapper();
        return mapper.readValue(json, clazz);
    }
}
